package com.gx.common.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author Liu-pj
 * @Date 2022/2/22 15:09
 * 拦截器配置
 **/
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private TenInfoInterceptor tenInfoInterceptor;

    /**
     * 添加拦截器配置
     *
     * @param registry 拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //1.添加自定义拦截器
        registry.addInterceptor(tenInfoInterceptor).
                //2.指定拦截器的url地址
                        addPathPatterns("/**").
                //3.指定不拦截的url地址
                        excludePathPatterns(
                        "/swagger-resources/**"
                        , "/webjars/**"
                        , "/v2/**"
                        , "/swagger-ui.html/**"
                        , "/doc.html/**"
                        , "/error/**"
                        , "/favicon.ico"
                );
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
